using System;
using Csla;
using System.Collections.Generic;
using ENT.PM.Datos.MysqlHelper;

namespace ENT.PM.Core.Core
{
    [Serializable]
    public class Log : BusinessBase<Log>
    {
        #region Business Methods

        private static PropertyInfo<Guid> IdProperty = RegisterProperty<Guid>(o => o.Id, "Name");
        public Guid Id
        {
            get { return GetProperty(IdProperty); }
            set { SetProperty(IdProperty, value); }
        }

        private static PropertyInfo<string> InfoLogProperty = RegisterProperty<string>(o => o.InfoLog, "Name");
        public string InfoLog
        {
            get { return GetProperty(InfoLogProperty); }
            set { SetProperty(InfoLogProperty, value); }
        }

        #endregion

        #region Validation Rules

        protected override void AddBusinessRules()
        {
            // TODO: add validation rules
            //ValidationRules.AddRule(RuleMethod, "");
        }

        #endregion

        #region Factory Methods

        public static Log NewLog()
        {
            return DataPortal.Create<Log>();
        }

        public static void DeleteLog(Guid id)
        {
            DataPortal.Delete<Log>(new SingleCriteria<Log, Guid>(id));
        }

        private Log()
        {
            LoadProperty(IdProperty,Guid.NewGuid());
        }

        #endregion

        #region Data Access

        [RunLocal]
        protected override void DataPortal_Create()
        {
            // TODO: load default values
            // omit this override if you have no defaults to set
            base.DataPortal_Create();
        }

        private void DataPortal_Fetch(SingleCriteria<Log, Guid> criteria)
        {
            
        }

        [Transactional(TransactionalTypes.TransactionScope)]
        protected override void DataPortal_Insert()
        {
            HelperMySql objhm = HelperMySql.ObtenerConexion("");
            var parametros = new MySql.Data.MySqlClient.MySqlParameter[1];
            parametros[0] = new MySql.Data.MySqlClient.MySqlParameter("Info", ReadProperty(InfoLogProperty));
            objhm.EjecutarStoreProcedure("InsertarLog", parametros);
        }

        [Transactional(TransactionalTypes.TransactionScope)]
        protected override void DataPortal_Update()
        {
            
        }

        [Transactional(TransactionalTypes.TransactionScope)]
        protected override void DataPortal_DeleteSelf()
        {
           
        }

        [Transactional(TransactionalTypes.TransactionScope)]
        private void DataPortal_Delete(SingleCriteria<Log, Guid> criteria)
        {
            
        }

        #endregion
    }

}
